/*
 * formateo de fechas
 * 
 */

package pruebas.fecha.joda.time;

import java.util.Locale;
import org.joda.time.Chronology;
import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;
import org.joda.time.chrono.BuddhistChronology;
import org.joda.time.chrono.GregorianChronology;
import org.joda.time.chrono.ISOChronology;
import org.joda.time.chrono.JulianChronology;
import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter;
import org.joda.time.format.DateTimeFormatterBuilder;
import org.joda.time.format.ISODateTimeFormat;

/**
 * clase para pruebas
 * @author grupo 06 - upc_dew 2010
 */
public class Formatear {
    public static void main(String[] args) {
        int anyo = 2010;
        int mes = 4;
        int dia = 15;
        int hour = 9;
        int min = 35;
        int sec = 0;
        int miliSec = 0;
        
        /* setear la zona horaria (DateTimeZone) */
        DateTimeZone DTZoneGMT = DateTimeZone.forID("GMT"); //Greenwich Mean Time: tiempo promedio del Observatorio de Greenwich, en Londres
        DateTimeZone DTZoneUTC = DateTimeZone.forID("UTC"); //Tiempo Universal Coordinado, es el sucesor de GMT
        //DateTimeZone DTZone = DateTimeZone.forID("Etc/GMT-5");
        //DateTimeZone DTZone = DateTimeZone.forID("Etc/GMT+0");
        //DateTimeZone DTZone = DateTimeZone.forID("Europe/Brussels");
        //DateTimeZone DTZone = DateTimeZone.forID("Europe/Paris");
        //DateTimeZone DTZone = DateTimeZone.forID("Europe/London");
        //DateTimeZone DTZone = DateTimeZone.forID("Asia/Tokyo");
        //DateTimeZone DTZone = DateTimeZone.forID("Asia/Bangkok");
        //DateTimeZone DTZone = DateTimeZone.forID("America/New_York");
        //DateTimeZone DTZone = DateTimeZone.forID("America/Sao_Paulo");
        //DateTimeZone DTZone = DateTimeZone.forID("Asia/Bangkok");
        
        /* setear el tipo de calendario (Chronology)*/
        Chronology chronoGregorian = GregorianChronology.getInstance(); // calendario gregoriano (Papa Gregorio XIII - 1582)
        Chronology chronoJulian = JulianChronology.getInstance(); // calendario juliano (Julio César - 46 a.C.)
        Chronology chronoBuddhist = BuddhistChronology.getInstance(); //calendario budista (Nacimiento de Buda 543 a.C.)
        Chronology chronoISO = ISOChronology.getInstance(); // calendario segun la norma ISO 8601 (2004)

        /* fecha actual indicando el tipo de calendario */
        DateTime dateTimeChronoGregorian = new DateTime(anyo, mes, dia, hour, min, sec, miliSec, chronoGregorian);
        DateTime dateTimeChronoBuddhist = new DateTime(anyo, mes, dia, hour, min, sec, miliSec, chronoBuddhist);
        DateTime dateTimeChronoJulian = new DateTime(anyo, mes, dia, hour, min, sec, miliSec, chronoJulian);
        DateTime dateTimeChronoISO = new DateTime(anyo, mes, dia, hour, min, sec, miliSec, chronoISO);

        /* fecha actual indicando la zona horaria */
        DateTime dateTimeZoneGMT = new DateTime(anyo, mes, dia, hour, min, sec, miliSec, DTZoneGMT);
        DateTime dateTimeZoneUTC = new DateTime(anyo, mes, dia, hour, min, sec, miliSec, DTZoneUTC);

        
        /* fecha actual por defecto (con referencia al sistema) del calendario y la zona horaria */
        DateTime dateTimeDefault = new DateTime(anyo, mes, dia, hour, min, sec, miliSec);
        DateTime dateNow = new DateTime();

        /* tipos de formato */
        DateTimeFormatter ordinalDate = ISODateTimeFormat.ordinalDate();
        String strOrdinalDate = ordinalDate.print(dateTimeDefault);

        DateTimeFormatter forPattern = DateTimeFormat.forPattern("dd MMM yyyy");
        String strForPattern = forPattern.withLocale(Locale.FRENCH).print(dateTimeDefault);

        DateTimeFormatter longDate = DateTimeFormat.longDate();
        String strLongDate = longDate.withLocale(Locale.ENGLISH).print(dateTimeDefault);

        DateTimeFormatter formatBuilder = new DateTimeFormatterBuilder().appendLiteral(" On ").appendDayOfWeekText().appendLiteral(" at ").appendClockhourOfHalfday(1).appendHalfdayOfDayText().toFormatter();
        String strFormatBuilder = formatBuilder.print(dateTimeDefault);

        System.out.println("La presentacion del formato de fechas es:  " );
        System.out.println("dateTimeDefault: " + dateTimeDefault);
        System.out.println("dateNow: " + dateNow);
        
        System.out.println("dateTimeChronoGregorian : " + dateTimeChronoGregorian);
        System.out.println("dateTimeChronoBuddhist : " + dateTimeChronoBuddhist);
        System.out.println("dateTimeChronoJulian : " + dateTimeChronoJulian);
        System.out.println("dateTimeChronoISO : " + dateTimeChronoISO);

        System.out.println("dateTimeZoneGMT : " + dateTimeZoneGMT);
        System.out.println("dateTimeZoneUTC : " + dateTimeZoneUTC);

        System.out.println("OrdinalDate dateTimeDefault: " + strOrdinalDate);
        System.out.println("PatternFormat dateTimeDefault: " + strForPattern);
        System.out.println("LognDate dateTimeDefault: " + strLongDate);
        System.out.println("FormatBuilder dateTimeDefault: " + strFormatBuilder);
    }

}
